<?php

namespace app\api\controller;

use think\facade\Request;
use think\facade\Cache;

class Config extends Common
{
    /**
     * @param Request $request
     * @param Cache $cache
     * @return \think\response\Json
     */
    public function show(Request $request, Cache $cache)
    {
        return $this->returnJson(
            200,
            'ok',
            json_decode($cache::get($request::param('name', 'system')), 256)
        );
    }

    /**
     * @param Request $request
     * @param Cache $cache
     * @return void
     */
    public function update(Request $request, Cache $cache)
    {
        $key = $request::param('name', 'system');
        $data = json_encode($request::param());
        return $this->returnJson(
            200,
            'ok',
            $cache::set($key, $data, 0)
        );
    }
}
